﻿// Example header text. Can be configured in the options.
using System;
using System.Data;
using vtech_frameWorks.DAO;
using vtech_frameWorks.Exceptions;
using vtech_frameWorks.Object;

namespace vtech_system.Role
{
    public class ClsRoleBS : ClsObjectBS
    {
        #region "Insert"
        public override void DoInsert(DataTable dt)
        {
            ClsRoleDAO obj = new ClsRoleDAO();
            try
            {
                conn = ClsBaseDbConnectionDAO.GetConnection();
                conn.Open();
                tran = conn.BeginTransaction();

                foreach (DataRow drow in dt.Rows)
                {
                    obj.Insert(drow);
                }

                tran.Commit();
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    ClsInformation.Information(ex.Message);
                }
                if (tran != null)
                {
                    tran.Rollback();
                }
            }
            finally
            {
                if (conn != null && conn.State != ConnectionState.Closed)
                {
                    conn.Close();
                }
            }
        }

        #endregion

        #region "Edit"
        public override void DoEdit(DataTable dt)
        {
            ClsRoleDAO obj = new ClsRoleDAO();
            try
            {
                conn = ClsBaseDbConnectionDAO.GetConnection();
                conn.Open();
                tran = conn.BeginTransaction();

                foreach (DataRow drow in dt.Rows)
                {
                    obj.Edit(drow);
                }

                tran.Commit();
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    ClsInformation.Information(ex.Message);
                }
                if (tran != null)
                {
                    tran.Rollback();
                }
            }
            finally
            {
                if (conn != null && conn.State != ConnectionState.Closed)
                {
                    conn.Close();
                }
            }
        }

        #endregion

        #region "Delete"
        public override void DoDelete(DataRow drow)
        {
            ClsRoleDAO obj = new ClsRoleDAO();
            try
            {
                conn = ClsBaseDbConnectionDAO.GetConnection();
                conn.Open();
                tran = conn.BeginTransaction();
                obj.Delete(drow);
                tran.Commit();
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    ClsInformation.Information(ex.Message);
                }
                if (tran != null)
                {
                    tran.Rollback();
                }
            }
            finally
            {
                if (conn != null && conn.State != ConnectionState.Closed)
                {
                    conn.Close();
                }
            }
        }

        #endregion

        #region GetAll
        public override DataTable GetAll()
        {
            ClsRoleDAO obj = new ClsRoleDAO();
            using (DsRole dsRole = new DsRole())
            {
                dsRole.DtRole.Merge(obj.GetAll());
                dtObject = dsRole.DtRole;
                return dsRole.DtRole;
            }
        }
        #endregion
    }
}